from views import page as pageBase

from api import api


class PurchaseOrder(object):
    # page = pageBase.saleOrder

    def test(self,):
        self.test_fields_view_get()
        # self.test_action_view_invoice()
        # self.test_create()

        # self.test_search()
        # self.test_browse()
        # self.test_write()

        # self.test_unlink()

        # self.test_line_create()
        # self.test_onchange2_line()

        # self.test_onchange222()
        # self.test_onchange2()

    def test_fields_view_get(self):
        obj = api.odooenv['purchase.order']
        # res = obj._onchange_spec()
        fgs = obj.fields_get([], ['type'])
        print('-----fgs,==', fgs)

        # for k, v in res.items():
        #     print(k, '-------:', v)

    def test_action_view_invoice(self):
        obj = api.odooenv['purchase.order']

        # args: [1],
        context = {
            'lang': 'zh_CN', 'tz': False, 'uid': 6,
            'allowed_company_ids': [2],
            'quotation_only': True, 'create_bill': True
        }

        res = obj.action_view_invoice(1, context=context)
        context.update(res['context'])

        context.update({
            'active_id': 1,
            'active_ids': [1],
            'active_model': "purchase.order",
        })

        for k, v in context.items():
            print(k, '-------:', v)

        obj = api.odooenv['account.move']

        res = obj.onchange2([], {}, [], context=context)
        print('-----move,==', res)

        # fgs = obj.fields_get([], ['type'])
        # fields = list(fgs.keys())
        # res = obj.default_get(fields, context=context)
        # print('-----move,==')
        # for k, v in res.items():
        #     print(k, '-------:', v)

        # res = obj.create(res, context=context)
        # print('-----move,==', res)
        # move_id = 12

        # res = obj.onchange2([move_id], res, [],  context=context)
        # print('-----move,==', res)

    def test_onchange2_line(self,):
        ids = []

        values = {
            'order_id': {
                'id': 20, 'display_name': 'S00021', 'state': 'draft', 'name': 'S00021', 'partner_id': 7, 'company_id': 1, 'user_id': 2, 'reference': None, 'note': 'www222', 'date_order': '2020-10-30 10:33:56', 'commitment_date': None, 'expected_date': '2020-11-03 15:40:26', 'amount_total': 10021, 'invoice_status': 'no', 'validity_date': None, 'invoice_ids': [], 'currency_id': 7, 'pricelist_id': 1, 'amount_untaxed': 10021, 'amount_tax': 0,
                'order_line': [[1, 17, {'id': 17, 'product_id': 1, 'name': '啤酒', 'product_uom_qty': 1001, 'product_uom': 1, 'product_uom_category_id': 1, 'price_unit': 10, 'price_total': 10010, 'price_subtotal': 10010, 'company_id': 1, 'virtual_available_at_date': -1, 'scheduled_date': '2020-11-03 15:39:52', 'warehouse_id': 1, 'qty_to_deliver': 1001, 'display_qty_widget': True}],
                               [0, -1, {'id': -1, 'product_id': 4, 'product_uom': 1, 'product_uom_category_id': 1, 'product_uom_qty': 11, 'price_unit': 1, 'state': 'draft', 'invoice_status': 'no', 'qty_delivered': 0,
                                        'qty_delivered_manual': 0, 'qty_delivered_method': 'stock_move', 'qty_to_deliver': 11, 'name': 'P1', 'price_subtotal': 11, 'price_total': 11, 'product_template_id': 4, 'product_type': 'consu'}]
                               ]
            },

            'id': -1, 'product_id': 4, 'product_uom': 1,
            'product_uom_category_id': 1, 'product_uom_qty': 11,
            'price_unit': 1, 'state': 'draft', 'invoice_status': 'no',
            'qty_delivered': 0, 'qty_delivered_manual': 0,
            'qty_delivered_method': 'stock_move', 'qty_to_deliver': 11,
            'name': 'P1', 'price_subtotal': 11, 'price_total': 11,
            'product_template_id': 4, 'product_type': 'consu'


        }

        field_name = 'product_uom_qty'

        field_onchange = {
            'name': '', 'product_id': '1', 'product_uom_qty': '1', 'product_uom': '1', 'price_unit': '1', 'price_subtotal': '', 'price_total': '1', 'state': '1', 'invoice_status': '1', 'product_uom_category_id': '', 'sequence': '', 'display_type': '', 'product_updatable': '', 'product_template_id': '', 'analytic_tag_ids': '', 'route_id': '1', 'product_type': '', 'virtual_available_at_date': '', 'qty_available_today': '', 'free_qty_today': '', 'scheduled_date': '', 'warehouse_id': '', 'qty_to_deliver': '', 'is_mto': '', 'display_qty_widget': '', 'qty_delivered': '1', 'qty_delivered_manual': '1', 'qty_delivered_method': '1', 'qty_invoiced': '1', 'qty_to_invoice': '1', 'customer_lead': '1', 'product_packaging': '1', 'tax_id': '1', 'discount': '1', 'currency_id': '', 'price_tax': '', 'company_id': ''

        }

        context = {'lang': 'zh_CN', 'tz': False,
                   'uid': 2, 'allowed_company_ids': [1]}

        res = api.odooenv['sale.order.line'].onchange2(
            ids, values, field_name, field_onchange, context=context)

        print(res)

        # print('--value-')
        # for r, v in res['value'].items():
        #     print(r, v)

    def test_default_get(self,):
        context = {
            'default_company_id': 2,
            'allowed_company_ids': [2]
        }

        fields_default_get = {
            "state": None,
            "name": None,
            "partner_id": None,

            "validity_date": None,
            "date_order": None,
            "payment_term_id": None,
            "order_line": None,
            "note": None,
            "amount_untaxed": None,
            "amount_tax": None,
            "amount_total": None,
            "user_id": None,
            "team_id": None,
            "company_id": None,
            "reference": None,
            "client_order_ref": None,
            "fiscal_position_id": None,
            "analytic_account_id": None,
            "invoice_status": None,
            "commitment_date": None,


            # "delivery_count": None,
            # "invoice_count": None,


            # "authorized_transaction_ids": None,
            # "picking_ids": None,

            # "sale_order_template_id": None,
            # "pricelist_id": None,
            # "currency_id": None,

            # "sale_order_option_ids": None,
            # "require_signature": None,
            # "require_payment": None,
            # "warehouse_id": None,
            # "incoterm": None,
            # "picking_policy": None,
            # "expected_date": None,
            # "effective_date": None,
            # "origin": None,
            # "campaign_id": None,
            # "medium_id": None,
            # "source_id": None,
            # "signed_by": None,
            # "signed_on": None,
            # "signature": None,
        }

        field_onchange = {
            "authorized_transaction_ids": "",
            "state": "1",
            "picking_ids": "1",
            "delivery_count": "",
            "invoice_count": "",
            "name": "",
            "partner_id": "1",
            "partner_invoice_id": "",
            "partner_shipping_id": "1",
            "sale_order_template_id": "1",
            "validity_date": "",
            "date_order": "1",
            "pricelist_id": "1",
            "currency_id": "1",
            "payment_term_id": "",
            "order_line": "1",
            "order_line.display_type": "",
            "order_line.sequence": "",
            "order_line.product_uom_category_id": "",
            "order_line.product_updatable": "",
            "order_line.product_id": "1",
            "order_line.invoice_status": "1",
            "order_line.qty_to_invoice": "1",
            "order_line.qty_delivered_manual": "1",
            "order_line.qty_delivered_method": "1",
            "order_line.price_total": "1",
            "order_line.price_tax": "",
            "order_line.price_subtotal": "",
            "order_line.product_uom_qty": "1",
            "order_line.product_uom": "1",
            "order_line.qty_delivered": "1",
            "order_line.qty_invoiced": "1",
            "order_line.product_packaging": "1",
            "order_line.price_unit": "1",
            "order_line.tax_id": "1",
            "order_line.discount": "1",
            "order_line.customer_lead": "1",
            "order_line.route_id": "1",
            "order_line.analytic_tag_ids": "",
            "order_line.name": "",
            "order_line.invoice_lines": "1",
            "order_line.state": "1",
            "order_line.company_id": "",
            "order_line.product_template_id": "",
            "order_line.product_type": "",
            "order_line.virtual_available_at_date": "",
            "order_line.qty_available_today": "",
            "order_line.free_qty_today": "",
            "order_line.scheduled_date": "",
            "order_line.warehouse_id": "",
            "order_line.qty_to_deliver": "",
            "order_line.is_mto": "",
            "order_line.display_qty_widget": "",
            "order_line.currency_id": "",
            "note": "",
            "amount_untaxed": "",
            "amount_tax": "",
            "amount_total": "",
            "sale_order_option_ids": "",
            "sale_order_option_ids.product_id": "1",
            "sale_order_option_ids.name": "",
            "sale_order_option_ids.quantity": "",
            "sale_order_option_ids.product_uom_category_id": "",
            "sale_order_option_ids.uom_id": "1",
            "sale_order_option_ids.price_unit": "",
            "sale_order_option_ids.discount": "",
            "sale_order_option_ids.is_present": "",
            "sale_order_option_ids.sequence": "",
            "user_id": "1",
            "team_id": "1",
            "company_id": "1",
            "require_signature": "",
            "require_payment": "",
            "reference": "",
            "client_order_ref": "",
            "fiscal_position_id": "1",
            "analytic_account_id": "",
            "invoice_status": "",
            "warehouse_id": "1",
            "incoterm": "",
            "picking_policy": "1",
            "commitment_date": "1",
            "expected_date": "",
            "effective_date": "",
            "origin": "",
            "campaign_id": "",
            "medium_id": "",
            "source_id": "",
            "signed_by": "",
            "signed_on": "",
            "signature": "",
            "__last_update": "",
            "message_follower_ids": "",
            "activity_ids": "",
            "message_ids": "",
            "message_attachment_count": ""

        }

        obj = api.odooenv['sale.order']

        fields = list(fields_default_get.keys())
        fieldsGet = obj.fields_get2(fields, ['type', 'selection', 'domain'])
        print('--fields_get--')
        for k, v in fieldsGet.items():
            print(k, ':',  v)

        # fieldsGet ok
        # 异步处理

        fields = list(fields_default_get.keys())

        result = obj.onchange2([], {}, [], field_onchange,
                               fields_default_get=fields, context=context)

        print('--default onchange--')
        for k, v in result['value'].items():
            print(k, ':',  v)

        print('--default onchange domain --', result['domain'])

        # 二次 fields get 前端 处理
        print('--fields_get--')
        for k, v in result['fields'].items():
            print(k, ':',  v)

        def fn(k, v): return fieldsGet[k]['type'] in [
            'selection', 'many2one'] and v and v[0] or v

        values = result['value']

        values = dict((k,  fn(k, v)) for k, v in values.items())
        print('-----,', values)

        values.update({'company_id': 1})

        print('-----,', values)

        result = obj.onchange2([], values, 'company_id',
                               field_onchange, context=context)

        print('--= onchange --', {'company_id': 1})
        for k, v in result['value'].items():
            print(k, ':',  v)

        print('--default onchange domain --', result['domain'])

        # 二次 fields get 前端 处理
        print('--fields_get--')
        for k, v in result['fields'].items():
            print(k, ':',  v)

    def test_onchange222(self,):
        ids = [20]

        values = {
            'display_name': 'S00021',
            'state': 'draft',
            'name': 'S00021',
            'partner_id': 7,
            'company_id': 1,
            'user_id': 2,
            'reference': None,
            'note': 'www222',
            'date_order': '2020-10-30 10:33:56',
            'commitment_date': None,
            'expected_date': '2020-11-03 03:29:41',
            'amount_total': 10000,
            "amount_tax": 0,
            'invoice_status': 'no',
            'validity_date': None,
            'invoice_ids': [],
            'order_line': [[2, 17, False], [2, 20, False]],
            'amount_untaxed': 10000
        }

        field_name = 'order_line'

        field_onchange = {
            'authorized_transaction_ids': '', 'state': '1', 'picking_ids': '1', 'delivery_count': '', 'invoice_count': '', 'name': '',
            'partner_id': '1', 'partner_invoice_id': '', 'partner_shipping_id': '1',
            'sale_order_template_id': '1', 'validity_date': '', 'date_order': '1', 'pricelist_id': '1',
            'currency_id': '1', 'payment_term_id': '', 'order_line': '1', 'note': '',
            'amount_untaxed': '', 'amount_tax': '', 'amount_total': '',
            'sale_order_option_ids': '', 'user_id': '1', 'team_id': '1', 'company_id': '1', 'require_signature': '',
            'require_payment': '', 'reference': '', 'client_order_ref': '', 'fiscal_position_id': '1',
            'analytic_account_id': '', 'invoice_status': '', 'warehouse_id': '1', 'incoterm': '', 'picking_policy': '1', 'commitment_date': '1',
            'expected_date': '', 'effective_date': '', 'origin': ''

        }

        context = {'lang': 'zh_CN', 'tz': False,
                   'uid': 2, 'allowed_company_ids': [1]}

        res = api.odooenv['sale.order'].onchange2(
            ids, values, field_name, field_onchange, context=context)

        # print(res)

        print('--value-')
        for r, v in res['value'].items():
            print(r, v)

    def test_onchange2(self,):

        print(' odoo, ')

        ids = [20]

        values = {
            # "id": 20,
            # "authorized_transaction_ids": [[6, False, []]],
            # "state": "draft",
            # "picking_ids": [],
            # "delivery_count": 0,
            # "invoice_count": 0,
            # "name": "S00021",
            # "partner_id": 7,
            # "partner_invoice_id": 7,
            # "partner_shipping_id": 7,
            # "sale_order_template_id": False,
            # "validity_date": False,
            # "date_order": "2020-10-30 10:33:56",
            # "pricelist_id": 1,
            # "currency_id": 7,
            # "payment_term_id": False,
            "order_line": [[2, 17, False], [2, 20, False]],
            # "note": "www222",
            "amount_untaxed": 10000,
            "amount_tax": 0,
            "amount_total": 10000,
            # "sale_order_option_ids": [],
            # "user_id": 2,
            # "team_id": 1,
            # "company_id": 1,
            # "require_signature": True,
            # "require_payment": False,
            # "reference": False,
            # "client_order_ref": False,
            # "fiscal_position_id": False,
            # "analytic_account_id": False,
            # "invoice_status": "no",
            # "warehouse_id": 1,
            # "incoterm": False,
            # "picking_policy": "direct",
            # "commitment_date": False,
            # "expected_date": "2020-11-03 03:28:43",
            # "effective_date": False,
            # "origin": False,
            # "campaign_id": False,
            # "medium_id": False,
            # "source_id": False,
            # "signed_by": False,
            # "signed_on": False,
            # "signature": False,
            # "__last_update": "2020-10-31 03:39:32",
            # "message_follower_ids": [[4, 118, False]],
            # "activity_ids": [],
            # "message_ids": [[4, 123, False], [4, 122, False]],
            # "message_attachment_count": 0
        }
        field_name = 'order_line'

        field_onchange = {
            # "authorized_transaction_ids": "",

            # "state": "1",

            # "picking_ids": "1",
            # "delivery_count": "",

            # "invoice_count": "",
            # "name": "",
            # "partner_id": "1",
            # "partner_invoice_id": "",
            # "partner_shipping_id": "1",
            # "sale_order_template_id": "1",
            # "validity_date": "",
            # "date_order": "1",
            # "pricelist_id": "1",
            # "currency_id": "1",
            # "payment_term_id": "",

            # "order_line": "1",
            # "order_line.display_type": "",
            # "order_line.sequence": "",
            # "order_line.product_uom_category_id": "",
            # "order_line.product_updatable": "",
            # "order_line.product_id": "1",
            # "order_line.invoice_status": "1",
            # "order_line.qty_to_invoice": "1",
            # "order_line.qty_delivered_manual": "1",
            # "order_line.qty_delivered_method": "1",
            # "order_line.price_total": "1",
            # "order_line.price_tax": "",
            # "order_line.price_subtotal": "",
            # "order_line.product_uom_qty": "1",
            # "order_line.product_uom": "1",
            # "order_line.qty_delivered": "1",
            # "order_line.qty_invoiced": "1",
            # "order_line.product_packaging": "1",
            # "order_line.price_unit": "1",
            # "order_line.tax_id": "1",
            # "order_line.discount": "1",
            # "order_line.customer_lead": "1",
            # "order_line.route_id": "1",
            # "order_line.analytic_tag_ids": "",
            # "order_line.name": "",
            # "order_line.invoice_lines": "1",
            # "order_line.state": "1",
            # "order_line.company_id": "",
            # "order_line.product_template_id": "",
            # "order_line.product_type": "",
            # "order_line.virtual_available_at_date": "",

            # "order_line.qty_available_today": "",
            # "order_line.free_qty_today": "",
            # "order_line.scheduled_date": "",
            # "order_line.warehouse_id": "",
            # "order_line.qty_to_deliver": "",
            # "order_line.is_mto": "",
            # "order_line.display_qty_widget": "",
            # "order_line.currency_id": "",

            # "note": "",
            "amount_untaxed": "",
            "amount_tax": "",

            "amount_total": "",

            # "sale_order_option_ids": "",
            # "sale_order_option_ids.product_id": "1",
            # "sale_order_option_ids.name": "",
            # "sale_order_option_ids.quantity": "",
            # "sale_order_option_ids.product_uom_category_id": "",
            # "sale_order_option_ids.uom_id": "1",
            # "sale_order_option_ids.price_unit": "",
            # "sale_order_option_ids.discount": "",
            # "sale_order_option_ids.is_present": "",
            # "sale_order_option_ids.sequence": "",

            # "user_id": "1",
            # "team_id": "1",
            # "company_id": "1",

            # "require_signature": "",
            # "require_payment": "",
            # "reference": "",
            # "client_order_ref": "",
            # "fiscal_position_id": "1",
            # "analytic_account_id": "",
            # "invoice_status": "",
            # "warehouse_id": "1",
            # "incoterm": "",
            # "picking_policy": "1",
            # "commitment_date": "1",
            "expected_date": "",
            # "effective_date": "",
            # "origin": "",
            # "campaign_id": "",
            # "medium_id": "",
            # "source_id": "",
            # "signed_by": "",
            # "signed_on": "",
            # "signature": "",
            # "__last_update": "",
            # "message_follower_ids": "",
            # "activity_ids": "",
            # "message_ids": "",
            # "message_attachment_count": ""
        }

        context = {"lang": "zh_CN", "tz": False, "uid": 2, "allowed_company_ids": [1],
                   #    "params": {"action": 318, "cids": 1, "id": 20, "menu_id": 189, "model": "sale.order", "view_type": "form"}
                   }

        res = api.odooenv['sale.order'].onchange2(
            ids, values, field_name, field_onchange, context=context)

        # print(res)

        print('--value-')
        for r, v in res['value'].items():
            print(r, v)
        # print('--domain-')
        # for r, v in res['domain'].items():
        #     print(r, v)
        # print('--fields-')
        # for r, v in res['fields'].items():
        #     if v['type'] == 'many2one':
        #         print(r, v)

    def test_search(self):
        domain = [('name', 'like', 'www')]
        domain = []
        self.page.showList(domain)
        print('sech ok --------,', self.page._name)
        print('sech ok --------,', self.page.store.dataLength)
        for r in self.page.dataList:
            print('sech ok --for------,', r)
        # return self.page.store.dataList

    def test_browse(self):
        rid = self.page.dataList[0]['id']
        # rid = 8
        print('--- in test, test_browse rid-1--', rid)
        dataDict = self.page.dataDict
        print('--- in test, test_browse dataDict-1--', dataDict)

        o2m_page = pageBase.saleOrderLine
        print('--- in test, test_browse line-1--', o2m_page.store.dataList)

        self.page.showView(rid)
        dataDict = self.page.dataDict
        print('--- in test, test_browse dataDict-2--', dataDict)
        print('--- in test, test_browse line-2--', o2m_page.store.dataList)

    def test_write(self):
        dataDict = self.page.store.dataDict
        formData = self.page.store.formData
        values = self.page.store.values
        print('--- in test, test_write-1-dataDict-', dataDict)
        print('--- in test, test_write-1-formData-', formData)
        print('--- in test, test_write--1-values:', values)
        rid = self.page.store.dataDict['id']
        self.page.showForm(rid)
        dataDict = self.page.store.dataDict
        formData = self.page.store.formData
        values = self.page.store.values
        print('--- in test, test_write-2-dataDict-', dataDict)
        print('--- in test, test_write-2-formData-', formData)
        print('--- in test, test_write-2-values:', values)

        input_value = ['note', 'www222']
        self.page.handleOnchange(*input_value)
        dataDict = self.page.store.dataDict
        formData = self.page.store.formData
        values = self.page.store.values
        print('--- in test, test_write-3-dataDict-', dataDict)
        print('--- in test, test_write-3-formData-', formData)
        print('--- in test, test_write-3-values:', values)

        # o2m 字段的处理
        o2m_field = 'order_line'
        # 1 设置 parent values, 初始化 fg
        self.page.InitO2mForm(o2m_field)

        self.test_new_line()

        # self.page.submitWrite(rid)
        # dataDict = self.page.store.dataDict
        # print('--- in test, dataDict--4-', dataDict)

    def test_create(self):
        self.test_create_show_form()
        self.test_create_edit_form()

        # o2m 字段的处理
        # 1 设置 parent values, 初始化 fg
        o2m_field = 'order_line'
        self.page.InitO2mForm(o2m_field)

        # o2m_model = 'saleOrderLine'
        # o2m_page = pageBase[o2m_model]

        # self.test_init_o2m_set(o2m_page)

        # 2 新增 / 编辑 line 字段
        self.test_new_line()

        values = self.page.store.values
        print('--1---, so, values, ', values)

        self.page.submitCreate()
        dataDict = self.page.store.dataDict
        print('--- in test, dataDict--3-', dataDict)

    def test_create_show_form(self):
        self.page.showForm()

        # fieldsGet = self.page.store.fieldsGet
        # print('  --- in test, fieldsGet-----', )
        # for k, v in fieldsGet.items():
        #     if v.get('type') == 'selection':
        #         print('  --%s, type:%s, options:%s' %
        #               (k, v.get('type'), v.get('options')))
        #     if v.get('type') in ['many2one', 'many2many']:
        #         print('  --%s, type:%s, options:%s, relation:%s, domain:%s'
        #               % (k, v.get('type'), v.get('options'),  v.get('relation'), v.get('domain'),))

        dataDict = self.page.store.dataDict
        formData = self.page.store.formData
        values = self.page.store.values
        print('--- in test, dataDict-1--', dataDict)
        print('--- in test, formData--1-', formData)
        print('--- in test, values--1-', values)

    def test_create_edit_form(self):
        input_value = ['partner_id', 7]
        self.page.handleOnchange(*input_value)
        # input_value = ['note', 'www122']
        # self.page.handleOnchange(*input_value)

        dataDict = self.page.store.dataDict
        formData = self.page.store.formData
        values = self.page.store.values
        print('--- in test, dataDict--2-', dataDict)
        print('--- in test, formData--2-', formData)
        print('--- in test, values--2-', values)

        # fieldsGet = self.page.store.fieldsGet
        # print('  --- in test, fieldsGet-----', )
        # for k, v in fieldsGet.items():
        #     if v.get('type') == 'selection':
        #         print('  --%s, type:%s, options:%s' %
        #               (k, v.get('type'), v.get('options')))
        #     if v.get('type') in ['many2one', 'many2many']:
        #         print('  --%s, type:%s, options:%s, relation:%s, domain:%s'
        #               % (k, v.get('type'), v.get('options'),  v.get('relation'), v.get('domain'),))

    def test_new_line(self):
        # o2m_model = 'saleOrderLine'
        # o2m_page = pageBase[o2m_model]

        o2m_field = 'order_line'

        # o2m 打开 新增 明细行
        self.page.showO2mForm(o2m_field)

        # o2m 新增 录入数据,
        self.page.o2m_onchange(o2m_field, 'product_id', 1)
        self.page.o2m_submit(o2m_field)

        # # o2m 查询 选中明细行,
        o2m_model = 'saleOrderLine'
        o2m_page = pageBase[o2m_model]
        lines = o2m_page.store.dataList
        line = lines[0]

        # o2m 打开 编辑 明细行,
        self.page.o2m_edit(o2m_field, line['id'])
        # o2m 编辑 明细行, 录入数据
        print('-- in tets, edit line , - ---')
        self.page.o2m_onchange(o2m_field, 'product_uom_qty', 1000)
        self.page.o2m_submit(o2m_field)

        # self.page.showO2mForm(o2m_field)
        # self.page.o2m_onchange(o2m_field, 'product_id', 4)
        # self.page.o2m_submit(o2m_field)
        # self.page.o2m_onchange(o2m_field, 'product_uom_qty', 100)
        # self.page.o2m_submit(o2m_field)

        # lines = o2m_page.store.dataList
        # line = lines[1]
        # self.page.o2m_del(o2m_field, line['id'])

        # lines = o2m_page.store.dataList
        # line = lines[1]
        # self.page.o2m_del(o2m_field, line['id'])

        # lines = o2m_page.store.dataList
        # line = lines[1]

        # self.page.o2m_del(o2m_field, line['id'])

        # # self.page.o2m_default_get_onchange(o2m_field)
        # # self.page.o2m_edit(o2m_field, 1, 'product_id', 4)

        # print('----so------, formData', self.page.store.formData)
        # print('----so------, values', self.page.store.values)
        # sols = self.page.store.values['order_line']
        # print('----so------, values')
        # for l in sols:
        #     print(l)

    def test_init_o2m_set(self, o2m_page):

        print('----1----line--, valuesForParent', )
        print(o2m_page.store.valuesForParent)
        print('----1------, line_fgs', )

        for k, v in o2m_page.store.fieldsGet.items():
            if v.get('type') == 'selection':
                print('  --%s, type:%s, options:%s' %
                      (k, v.get('type'), v.get('options')))
            if v.get('type') in ['many2one', 'many2many']:
                print('  --%s, type:%s, options:%s, relation:%s, domain:%s'
                      % (k, v.get('type'), v.get('options'),  v.get('relation'), v.get('domain'),))

    def test_line_create(self):

        obj = api.odooenv['sale.order.line']
        values = {
            "product_id": 1,

            # "sequence": 10,
            # "display_type": False,
            # "product_updatable": True,
            # "product_uom_qty": 1,
            # "qty_delivered": 0,
            # "qty_delivered_manual": 0,
            # "customer_lead": 0,
            # "product_packaging": False,
            # "price_unit": 0,
            # "discount": 0,
            # "state": "draft",
            # "invoice_status": "no",
            # "product_uom_category_id": False,

            # "product_template_id": False,
            # "name": False,
            # "analytic_tag_ids": [[6, False, []]],
            # "route_id": False,
            # "product_type": False,
            # "virtual_available_at_date": 0,
            # "qty_available_today": 0,
            # "free_qty_today": 0,
            # "scheduled_date": False,
            # "warehouse_id": False,
            # "qty_to_deliver": 1,
            # "is_mto": False,
            # "display_qty_widget": False,
            # "qty_delivered_method": "manual",
            # "qty_invoiced": 0,
            # "qty_to_invoice": 0,
            # "product_uom": False,
            # "tax_id": [[6, False, []]],
            # "price_subtotal": 0,
            # "price_total": 0,
            # "currency_id": False,
            # "price_tax": 0,

            # "company_id": False,

            "order_id": {
                "state": "draft",
                "name": "新建",
                "sale_order_template_id": False,
                "validity_date": False,

                "date_order": "2020-10-28 00:27:50",
                "partner_id": 7,
                        #  "partner_invoice_id": 7,
                        #  "partner_shipping_id": 7,
                         "pricelist_id": 1,
                         "currency_id": 7,
                        #  "user_id": 2,
                        #  "team_id": 1,
                        #  "company_id": 1,

                "amount_untaxed": 0,
                "amount_tax": 0,
                "amount_total": 0,

                #  "note": "",
                #  "require_signature": True,
                #  "require_payment": False,
                #  "warehouse_id": 1,
                #  "picking_policy": "direct",
                #  "authorized_transaction_ids": [[6, False, []]],
                #  "picking_ids": [],
                #  "delivery_count": 0,
                #  "invoice_count": 0,
                #  "payment_term_id": False,

                "order_line": [
                    #  [0,
                    #   "virtual_328",
                    #   {
                    #       "sequence": 10,
                    #       "display_type": False,
                    #       "product_updatable": True,
                    #       "product_uom_qty": 1,
                    #       "qty_delivered": 0,
                    #       "qty_delivered_manual": 0,
                    #       "customer_lead": 0,
                    #       "product_packaging": False,
                    #       "price_unit": 0,
                    #       "discount": 0,
                    #       "state": "draft",
                    #       "invoice_status": "no",
                    #       "product_uom_category_id": False,
                    #       "product_id": 1,
                    #       "product_template_id": False,
                    #       "name": False,
                    #       "route_id": False,
                    #       "product_type": False,
                    #       "virtual_available_at_date": 0,
                    #       "qty_available_today": 0,
                    #       "free_qty_today": 0,
                    #       "scheduled_date": False,
                    #       "warehouse_id": False,
                    #       "qty_to_deliver": 1,
                    #       "is_mto": False,
                    #       "display_qty_widget": False,
                    #       "qty_delivered_method": "manual",
                    #       "qty_invoiced": 0,
                    #       "qty_to_invoice": 0,
                    #       "product_uom": False,
                    #       "price_subtotal": 0,
                    #       "price_total": 0,
                    #       "currency_id": False,
                    #       "price_tax": 0,
                    #       "company_id": False
                    #   }]
                ],


                # "sale_order_option_ids": [],
                # "reference": False,
                # "client_order_ref": False,
                # "fiscal_position_id": False,
                # "analytic_account_id": False,
                # "invoice_status": "no",
                # "incoterm": False,
                # "commitment_date": False,
                # "expected_date": False,
                # "effective_date": False,
                # "origin": False,

                # "campaign_id": False,
                # "medium_id": False,
                # "source_id": False,
                # "signed_by": False,
                # "signed_on": False,
                # "signature": False,
                # "__last_update": False,
                # "message_follower_ids": [],
                # "activity_ids": [],
                # "message_ids": [],
                # "message_attachment_count": 0
            }
        }

        field_onchange = {




            "sequence": "",
            "display_type": "",
            "product_uom_category_id": "",
            "product_updatable": "",
            "product_id": "1",
            "product_template_id": "",
            "name": "",
            "analytic_tag_ids": "",
            "route_id": "1",
            "product_uom_qty": "1",
            "product_type": "",
            "virtual_available_at_date": "",
            "qty_available_today": "",
            "free_qty_today": "",
            "scheduled_date": "",
            "warehouse_id": "",
            "qty_to_deliver": "",
            "is_mto": "",
            "display_qty_widget": "",
            "qty_delivered": "1",
            "qty_delivered_manual": "1",
            "qty_delivered_method": "1",
            "qty_invoiced": "1",
            "qty_to_invoice": "1",
            "product_uom": "1",
            "customer_lead": "1",
            "product_packaging": "1",
            "price_unit": "1",
            "tax_id": "1",
            "discount": "1",
            "price_subtotal": "",
            "price_total": "1",
            "state": "1",
            "invoice_status": "1",
            "currency_id": "",
            "price_tax": "",
            "company_id": ""

        }

        res = obj.onchange([], values, 'product_id', field_onchange)

        print(res)


purchaseOrder = PurchaseOrder()


# ss = {
#         "jsonrpc": "2.0",
#         "id": 497507716,
#         "result": {

#             "value": {
#                 "ref": "",
#                 "company_currency_id": [7, "CNY"],

#                 "line_ids": [
#                     [5],
#                     [0, 0, {
#                         "move_name": "/",
#                         "date": "2020-11-06",
#                         "company_id": [2, "Comp1"],
#                         "company_currency_id": [7, "CNY"],
#                         "country_id": false,
#                         "account_id": [121, "220200 \u5e94\u4ed8\u8d26\u6b3e"],
#                         "account_internal_type": "payable",
#                         "sequence": 10,
#                         "name": "",
#                         "quantity": 1.0,
#                         "price_unit": -4000.0,
#                         "discount": 0.0,
#                         "debit": 0.0,
#                         "credit": 4000.0,
#                         "amount_currency": 0.0,
#                         "price_subtotal": -4000.0,
#                         "price_total": -4000.0,
#                         "date_maturity": "2020-11-06",
#                         "currency_id": false,
#                         "partner_id": [12, "\u53ef\u53e3\u53ef\u4e50"],
#                         "product_uom_id": false,
#                         "product_id": false,
#                         "payment_id": false,
#                         "tax_ids": [[5]],
#                         "tax_line_id": false,
#                         "tax_group_id": false,
#                         "tax_base_amount": 0.0,
#                         "tax_exigible": true,
#                         "tax_repartition_line_id": false,
#                         "tag_ids": [[5]],
#                         "analytic_account_id": false,
#                         "analytic_tag_ids": [[5]],
#                         "recompute_tax_line": false,
#                         "display_type": false,
#                         "is_rounding_line": false,
#                         "exclude_from_invoice_tab": true,
#                         "asset_category_id": false,
#                         "purchase_line_id": false}],

#                     [0, 0, {
#                         "move_name": "/",
#                         "date": "2020-11-06",
#                         "company_id": [2, "Comp1"],
#                         "company_currency_id": [7, "CNY"],
#                         "country_id": false,
#                         "account_id": [93, "140200 \u5728\u9014\u7269\u8d44"],
#                         "account_internal_type": "other",
#                         "sequence": 10,
#                         "name": "P00001: \u53ef\u4e50",
#                         "quantity": 1000.0,
#                         "price_unit": 4.0,
#                         "discount": 0.0,
#                         "debit": 4000.0,
#                         "credit": 0.0,
#                         "amount_currency": 0.0,
#                         "price_subtotal": 4000.0,
#                         "price_total": 4000.0,
#                         "date_maturity": false,
#                         "currency_id": false,
#                         "partner_id": [12, "\u53ef\u53e3\u53ef\u4e50"],
#                         "product_uom_id": [1, "\u4ef6"],
#                         "product_id": [4, "\u53ef\u4e50"],
#                         "payment_id": false,
#                         "tax_ids": [[5]],
#                         "tax_line_id": false,
#                         "tax_group_id": false,
#                         "tax_base_amount": 0.0,
#                         "tax_exigible": true,
#                         "tax_repartition_line_id": false,
#                         "tag_ids": [[5]],
#                         "analytic_account_id": false,
#                         "analytic_tag_ids": [[5]],
#                         "recompute_tax_line": false,
#                         "display_type": false,
#                         "is_rounding_line": false,
#                         "exclude_from_invoice_tab": false,
#                         "asset_category_id": false,
#                         "purchase_line_id": [1, "\u53ef\u4e50"]
#                     }]
#                 ],

#                 "commercial_partner_id": [12, "\u53ef\u53e3\u53ef\u4e50"],
#                 "amount_untaxed": 4000.0,
#                 "amount_total": 4000.0,
#                 "amount_residual": 4000.0,
#                 "amount_by_group": [],
#                 "invoice_payment_state": "not_paid",
#                 "invoice_date_due": "2020-11-06",
#                 "invoice_payment_ref": "",

#                 "invoice_line_ids": [
#                     [5],
#                     [0, 0, {
#                         "move_name": "/",
#                         "date": "2020-11-06",
#                         "parent_state": "draft",
#                         "company_id": [2, "Comp1"],
#                         "company_currency_id": [7, "CNY"],
#                         "account_id": [93, "140200 \u5728\u9014\u7269\u8d44"],
#                         "account_internal_type": "other",
#                         "sequence": 10,
#                         "name": "P00001: \u53ef\u4e50",
#                         "quantity": 1000.0,
#                         "price_unit": 4.0,
#                         "discount": 0.0,
#                         "debit": 4000.0,
#                         "credit": 0.0,
#                         "amount_currency": 0.0,
#                         "price_subtotal": 4000.0,
#                         "price_total": 4000.0,
#                         "date_maturity": false,
#                         "currency_id": false,
#                         "partner_id": [12, "\u53ef\u53e3\u53ef\u4e50"],
#                         "product_uom_id": [1, "\u4ef6"],
#                         "product_id": [4, "\u53ef\u4e50"],
#                         "tax_ids": [[5]],
#                         "tax_line_id": false,
#                         "tax_base_amount": 0.0,
#                         "tax_exigible": true,
#                         "tax_repartition_line_id": false,
#                         "tag_ids": [[5]],
#                         "analytic_account_id": false,
#                         "analytic_tag_ids": [[5]],
#                         "recompute_tax_line": false,
#                         "display_type": false,
#                         "is_rounding_line": false,
#                         "exclude_from_invoice_tab": false,
#                         "always_set_currency_id": [7, "CNY"],
#                         "asset_category_id": false,
#                         "purchase_line_id": [1, "\u53ef\u4e50"]
#                     }]
#                 ],

#                 "invoice_payments_widget": "false",
#                 "invoice_sequence_number_next": "0001",
#                 "invoice_sequence_number_next_prefix": "\u8d26\u5355/2020/",
#                 "invoice_filter_type_domain": "purchase",
#                 "bank_partner_id": [12, "\u53ef\u53e3\u53ef\u4e50"],
#                 "purchase_id": false,
#                 "partner_shipping_id": [12, "\u53ef\u53e3\u53ef\u4e50"]

#             }

#         }

#     }
